package com.zx._10_设计模式.行为型模式.责任链模式.demo3;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

public class ExecuteCenter {

    Set<BaseExecuteProcessor> processorSet = new HashSet<BaseExecuteProcessor>();

    public void execute(String type, String params) {
        for (BaseExecuteProcessor executeProcessor : getProcessors(type)) {
            executeProcessor.execute(params);
        }
    }

    private List<BaseExecuteProcessor> getProcessors(String type) {
        return processorSet.stream().filter(processor -> type.equals(processor.getSupportType()))
                .collect(Collectors.toList());
    }
}
